<?php

/**
 * NOTICE OF LICENSE
 *
 * THIS SOURCE FILE IS PART OF EVEBIT'S PRIVATE PROJECT.
 * 
 * DO NOT USE THIS FILE IN OTHER PLACE.
 *
 * @category    ChinaWanderer
 * @package     Default
 * @subpackage  Controller
 * @author      Chen Qiao <chen.qiao@evebit.com>
 * @version     $$Id: IndexController.php 1455 2011-06-29 05:00:09Z zuo.fujie $$
 * @copyright   Copyright (c) 2011 Evebit Inc. China (http://www.evebit.com)
*/

/**
 * default controller for frontend
 * 
 * login,show home page,edit user information
 * 
 * @package     Default
 * @subpackage  Controller
 * @author      Chen Qiao <chen.qiao@evebit.com>
 * @version     $$Id: IndexController.php 1455 2011-06-29 05:00:09Z zuo.fujie $$
 */
class Default_IndexController extends Evebit_Controller_Action_Frontend {
	/**
	 * default action of the index controller
	 * 
	 * view the home page of the website
	 * 
	 */
	public function indexAction() {		
		//$this->view->layout ()->setLayout ( 'default' );
		$user = Zend_Auth::getInstance ()->getIdentity ();
		$this->view->user = $user;
	}

	public function ajaxCreateMenuAction(){
		$content = $this->getRequest()->getParam('content');
		if ($content){
			$handle = fopen('application/modules/blocks/frontend-views/scripts/menu.phtml', 'w+');
			fwrite($handle, $content);
			fclose($handle);
		}
		exit;
	}
	
	public function ajaxGetMenuAction(){
		$filename = 'application/modules/blocks/frontend-views/scripts/menu.phtml';
		$handle = fopen($filename, 'rb');
		$content = fread($handle, filesize($filename));
		fclose($handle);
		echo $content;
		exit;
	}
	
    public function ajaxCreateFooterAction(){
		$content = $this->getRequest()->getParam('content');
		if ($content){
			$handle = fopen('application/modules/blocks/frontend-views/scripts/ajax-footer.phtml', 'w+');
			fwrite($handle, $content);
			fclose($handle);
		}
		exit;
	}
	
	public function ajaxGetFooterAction(){
		$filename = 'application/modules/blocks/frontend-views/scripts/ajax-footer.phtml';
		$handle = fopen($filename, 'rb');
		$content = fread($handle, filesize($filename));
		fclose($handle);
		echo $content;
		exit;
	}
	
	public function ajaxGetMassageAction(){
		$filename = 'application/modules/blocks/frontend-views/scripts/ajax-get-message.phtml';
		$handle = fopen($filename, 'rb');
		if (filesize($filename)){
			$content = fread($handle, filesize($filename));
		}else {
			$content = null;
		}
		fclose($handle);
		
		$this->getSession()->clearMessages();
	    echo $content;
	    exit;
	}
}